package com.foxzzz.temporary;

import java.util.HashSet;
import java.util.Set;

public class Solution3 {
    public int lengthOfLongestSubstring(String s) {
        int max=0;
        char[] chs=s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            int j = i+1;
            Set<Character> set=new HashSet<>();
            set.add(chs[i]);
            for (; j < s.length(); j++) {
                if(set.contains(chs[j]))
                    break;
                set.add(chs[j]);
            }
            max=j-i>max?j-i:max;
            if(s.length()-i<=max)
                break;
        }
        return max;
    }

        public int lengthOfLongestSubstring1(String s) {
            int  size,i=0,j,k,max=0;
            size = s.length();
            char[] chars=s.toCharArray();
            for(j = 0;j<size;j++){
               //在i,j中间扫描有没有下标和j相等的
                for(k = i;k<j;k++)
                    if(chars[k]==chars[j]){
                        i = k+1;
                        break;
                    }
                if(j-i+1 > max)
                    max = j-i+1;
            }
            return max;
        }

    public static void main(String[] args) {
        new Solution3().lengthOfLongestSubstring1("abcabcbb");
    }
}
